package com.ptt.sqmonmobile;

import android.app.Activity;
import android.content.Intent;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationManager;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
import android.widget.Toast;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.GoogleMap.OnMyLocationChangeListener;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import com.ptt.sqm.util.AppUtil;

public class GooglemapActivity extends Activity {

	GoogleMap map;

	boolean isCurrentFirst;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_googlemap);

		Intent it = getIntent();
		double lat = it.getDoubleExtra(AppUtil.LATITUDE, 0);
		double lon = it.getDoubleExtra(AppUtil.LONGTITUDE, 0);

		map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
				.getMap();
		map.setOnMyLocationChangeListener(new OnMyLocationChangeListener() {

			@Override
			public void onMyLocationChange(Location location) {
				// TODO Auto-generated method stub
				if (!isCurrentFirst) {
					CameraPosition camPositon = new CameraPosition.Builder()
							.target(new LatLng(location.getLatitude(), location
									.getLongitude())).zoom(30f).build();
					map.animateCamera(CameraUpdateFactory
							.newCameraPosition(camPositon));
					
					
					 Toast.makeText(getApplicationContext(), String.valueOf(location
								.getLatitude()) + " , " +
					 String.valueOf(location
								.getLongitude()) ,
					 Toast.LENGTH_LONG).show();
					
					isCurrentFirst = true;
				}
			}
		});


		map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
				.getMap();
		if (map != null) {
			map.setMyLocationEnabled(true);

		}
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// TODO Auto-generated method stub
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}
}
